package com.example.todolist.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig {

    @Value("${todo.mq.exchange}")
    private String exchangeName;

    @Value("${todo.mq.queue}")
    private String queueName;

    @Value("${todo.mq.routing-key}")
    private String routingKey;

    @Bean
    public DirectExchange todoExchange() {
        return new DirectExchange(exchangeName);
    }

    @Bean
    public Queue todoQueue() {
        return new Queue(queueName, true);
    }

    @Bean
    public Binding todoBinding() {
        return BindingBuilder.bind(todoQueue())
                .to(todoExchange())
                .with(routingKey);
    }
}